package com.xpec.c4.game.login;

import org.jgroups.logging.Log;
import org.jgroups.logging.LogFactory;

import com.ms.service.module.zone.action.LoginZoneAction;
import com.xpec.c4.game.common.VerifyInfoNotifyMsg;
import com.xpec.c4.game.utility.GameUtility;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.annotations.MessageType;
import com.xpec.c4.service.annotations.Name;
import com.xpec.c4.service.contexts.ScopeType;


@Name(scopeType=ScopeType.SESSION)
public class LoginVerifyAction {
	
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(LoginVerifyAction.class);

	// @In
	// @Out(scopeType = ScopeType.SESSION)
	// public String sessionID;

	
	@MessageType(typeCode = MessageTypes.S_LOGIN_VERIFYCODE_RESPONSE)	
	public void onRecvVerifyCodeResult(VerifyInfoNotifyMsg info){
		if(info == null){
			log.error("onRecvVerifyCodeResult response result == null");
			return;
		}
		
		if(info.getResult() == VerifyInfoNotifyMsg.VERIFY_SUCCESS){
			if(log.isInfoEnabled()){
				log.info(LoginModule.LOGIN_TRACE_LOG_STRING+" method: "+GameUtility.getCurMethodName()+" s: "+info.getSessionID().toString()+"/g: "+info.getVerifyInfo().getUserId().toString());
			}
			if(info.getVerifyType() == VerifyInfoNotifyMsg.VERIFY_TYPE_LOGIN || info.getVerifyType() == VerifyInfoNotifyMsg.VERIFY_TYPE_LOGIN_ZONE_CLOSING){		
				
				info.getVerifyInfo().getUserId();
				if(info.getVerifyInfo() != null){
					CharacterLoginProcLogic.onRecvVerfyCodeNotifyResult(info.getVerifyInfo(), info.getModuleName(), info.getSessionID());
				}
			}
			else if(info.getVerifyType() == VerifyInfoNotifyMsg.VERIFY_TYPE_SWITCHZONE){
				//TODO:切換ZONE的時候可寫在此
			}
			
		}
		else{
			log.error("onRecvVerifyCodeResult result fail errCode:" + info.getResult() + " , type:" + info.getVerifyType() + " ,info:" + info.getVerifyInfo());
			
			LoginZoneAction.sendPlayerVerifyResultError(info.getResult(), info.getSessionID());

		}
	}
	
}
